﻿Imports System.Data.OleDb
Public Class KhachHangDAO
    Public Function Insert(ByVal tmp As KhachHangDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into KhachHang (HoTen,QueQuan,NgaySinh,CMND,MaLoai) values (@HoTen,@QueQuan,@NgaySinh,@CMND,@MaLoai)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        Dim para1, para2, para3, para4, para5 As OleDbParameter
        para1 = New OleDbParameter("@HoTen", tmp.HoTen)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@QueQuan", tmp.QueQuan)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@MaLoai", tmp.MaLoai)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@NgaySinh", tmp.NgaySinh)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@CMND", tmp.CMND)
        cmd.Parameters.Add(para5)
        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As KhachHangDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "Update KhachHang set HoTen=@HoTen,QueQuan=@QueQuan,NgaySinh=@NgaySinh,CMND=@CMND,MaLoai=@MaLoai where MaKhachHang=@MaKhachHang "
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        Dim para6, para1, para2, para3, para4, para5 As OleDbParameter
        para3 = New OleDbParameter("MaKhachHang", tmp.MaKhachHang)
        cmd.Parameters.Add(para3)
        para1 = New OleDbParameter("@HoTen", tmp.HoTen)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@QueQuan", tmp.QueQuan)
        cmd.Parameters.Add(para2)
        para4 = New OleDbParameter("@NgaySinh", tmp.NgaySinh)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@CMND", tmp.CMND)
        cmd.Parameters.Add(para5)
        para6 = New OleDbParameter("@MaLoai", tmp.MaLoai)
        cmd.Parameters.Add(para6)
        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As KhachHangDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from KhachHang where MaKhachHang=@MaKhachHang"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@MaKhachHang", tmp.MaKhachHang)
        cmd.Parameters.Add(para1)
        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function GetTable(ByVal t As String) As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = t
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Function GetValue(ByVal t As String) As String
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = t
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        Dim kq As String = cmd.ExecuteScalar()
        Return kq
    End Function


    Public Function DK_Insert(ByVal tmp As KhachHangDTO) As Integer

        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into KhachHang (HoTen,QueQuan,NgaySinh,CMND,ID,Pass) values (@HoTen,@QueQuan,@NgaySinh,@CMND,@ID,@Pass)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        Dim para1, para2, para3, para4, para5, para6 As OleDbParameter
        para1 = New OleDbParameter("@HoTen", tmp.HoTen)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@QueQuan", tmp.QueQuan)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@NgaySinh", tmp.NgaySinh)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@CMND", tmp.CMND)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@ID", tmp.IDKhachHang)
        cmd.Parameters.Add(para5)
        para6 = New OleDbParameter("@Pass", tmp.PassKhachHang)
        cmd.Parameters.Add(para6)
        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function
End Class
